package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Staff;

import java.util.ArrayList;

public class OtherStaffDao implements BaseStaffDao{
    static ArrayList<Staff> staffs = new ArrayList<>();

    public Staff[] findAllStaff() {
        Staff[] staff = new Staff[staffs.size()];
        for (int i = 0; i < staff.length; i++) {
            staff[i] = staffs.get(i);
        }
        return staff;
    }

    public boolean addStaff(Staff staff) {
        staffs.add(staff);
        return true;
    }

    public boolean sIdExist(String sId) {
        for (int i = 0; i < staffs.size(); i++) {
            if (staffs.get(i) != null && sId.equals(staffs.get(i).getId())){
                return true;
            }
        }
        return false;
    }

    public void deleteStaff(String sId) {
        for (int i = 0; i < staffs.size(); i++) {
            if (staffs.get(i) != null && sId.equals(staffs.get(i).getId())){
                staffs.remove(i);
            }
        }
    }

    public void updateStaff(Staff updateStaff) {
        String updateId = updateStaff.getId();
        for (int i = 0; i < staffs.size(); i++) {
            if (staffs.get(i) != null && updateId.equals(staffs.get(i).getId())){
                staffs.set(i,updateStaff);
            }
        }
    }
}
